<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <title></title>
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/vue.min.js"></script>
    <style>
        #app{
            background-color: #d0d5d8;
        }
    </style>
</head>
<body>
<div id="app">
    <div v-for="record in results.records">
        <hr>
        <h3>{{record.title}}</h3>
        <div v-for="content in record.content">
            <p>{{content}}</p>
        </div>
        答案：
        <div v-for="answer in record.answer">
            <div>{{answer}}</div>&nbsp;&nbsp;
        </div>
    </div>
    <button @click="prePage">上一页</button>
    <button @click="nextPage">下一页</button>
</div>
<script type="text/javascript">
    new Vue({
        el:"#app",
        data:{
            subjectId:0,
            results:[],
            nowPage:1
        },
        mounted:function () {
            let that=this
            that.subjectId=$.getUrlParam("subjectId")
            $.ajax({
                url:"/question/searchAll/"+that.nowPage+"?subjectId="+that.subjectId,
                type:"GET",
                success:function (results) {
                    if(results.code==582){
                        alert(results.msg)
                        history.back()
                    }
                    that.results=results.data
                    console.log(that.results)
                }
            })
        },

        methods:{
            nextPage:function () {
                let that=this
                that.nowPage=that.results.current+1
                if(that.nowPage>that.results.pages){
                    that.nowPage-=1
                }
                $.ajax({
                    url:"/question/searchAll/"+that.nowPage+"?subjectId="+that.subjectId,
                    type:"GET",
                    success:function (results) {
                        that.results=results.data
                        console.log(that.results)
                    }
                })
            },
            prePage:function () {
                let that=this
                that.nowPage=that.results.current-1
                if(that.nowPage<1){
                    that.nowPage+=1
                }
                $.ajax({
                    url:"/question/searchAll/"+that.nowPage+"?subjectId="+that.subjectId,
                    type:"GET",
                    success:function (results) {
                        that.results=results.data
                        console.log(that.results)
                    }
                })
            }
        }
    })
</script>

</body>
</html>